<template>
  <div>
    <quill-editor
      ref="myQuillEditor"
      :content="agreement"
      :options="editorOption"
      style="height: 400px;margin-right:15px;"
      class="ql-editor"
      @change="onEditorBlur1($event)"
    />
  </div>
</template>

<script>
import { quillEditor } from 'vue-quill-editor'
import * as Quill from 'quill'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
// 引用字号和字体css
import '@/styles/quillEditor.css'
// 设置字体大小
const fontSizeStyle = Quill.import('attributors/style/size') // 引入这个后会把样式写在style上
fontSizeStyle.whitelist = ['12px', '14px', '16px', '18px', '20px', '24px', '28px', '32px', '36px']
Quill.register(fontSizeStyle, true)
// 设置字体样式
const Font = Quill.import('attributors/style/font') // 引入这个后会把样式写在style上
const fonts = [
  'SimSun',
  'SimHei',
  'Microsoft-YaHei',
  'KaiTi',
  'FangSong'
]
Font.whitelist = fonts // 将字体加入到白名单
Quill.register(Font, true)
// 设置文字水平方式
var Align = Quill.import('attributors/style/align')
Align.whitelist = ['right', 'center', 'justify']
Quill.register(Align, true)
var Direction = Quill.import('attributors/style/direction')
Quill.register(Direction, true)
// var Indent = Quill.import('attributors/style/indent')
// Quill.register(Indent, true)

// 工具栏
const toolbarOptions = [
  ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线 -----['bold', 'italic', 'underline', 'strike']
  [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色-----[{ color: [] }, { background: [] }]
  [{ align: [] }], // 对齐方式-----[{ align: [] }]
  [{ size: fontSizeStyle.whitelist }], // 字体大小-----[{ size: ['small', false, 'large', 'huge'] }]
  // [{ font: fonts }], // 字体种类-----[{ font: [] }]
  [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
  // [{ direction: 'ltl' }], // 文本方向-----[{'direction': 'rtl'}]
  // [{ direction: 'rtl' }], // 文本方向-----[{'direction': 'rtl'}]
  [{ indent: '-1' }, { indent: '+1' }], // 缩进-----[{ indent: '-1' }, { indent: '+1' }]
  [{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表-----[{ list: 'ordered' }, { list: 'bullet' }]
  [{ script: 'sub' }, { script: 'super' }], // 上标/下标-----[{ script: 'sub' }, { script: 'super' }]
  ['blockquote', 'code-block'], // 引用  代码块-----['blockquote', 'code-block']
  ['clean'], // 清除文本格式-----['clean']
  ['link'] // 链接、图片、视频-----['link', 'image', 'video']
]

export default {
  name: 'QuillEditor',
  components: {
    quillEditor
  },
  props: {
    editorOption: {
      type: Object,
      default: function() {
        return { placeholder: '请输入需要编写的内容...',
          modules: {
            toolbar: toolbarOptions

          }}
      }
    },
    agreement: {
      type: String,
      default: ''
    }
  },
  methods: {
    onEditorBlur1({ quill, html, text }) {
      this.$emit('update:agreement', html)
      console.log('editor blur!', this.agreement)
    }
  }
}
</script>

<style scoped lang="scss"
>

</style>
